package org.dreamfly.core.dao.impl;

import org.dreamfly.core.action.searchInfo;
import org.dreamfly.core.bean.SzRadio;
import org.dreamfly.core.dao.RadioDAO;
import org.dreamfly.core.util.HTMLInputFilter;
import org.hibernate.Session;
import org.hibernate.Transaction;

import java.util.List;


public class RadioDAOImpl extends BaseDAOImpl<SzRadio,Long> implements RadioDAO{

	/* (non-Javadoc)
	 * @see org.dreamfly.core.dao.RadioDAO#normalSearch(java.lang.String)
	 */
	@Override
	public List<SzRadio> normalSearch(String keyWords) {
        List<SzRadio> radioes= searchInfo.search(getSession(),keyWords);
        return radioes;
	}

    @Override
    public void saveInfo(SzRadio radio) {
        HTMLInputFilter inputFilter = new HTMLInputFilter();
		Session session = this.getSession();
		Transaction tx = session.beginTransaction();
		
		SzRadio SzRadio = (SzRadio) session.load(SzRadio.class, radio.getId());
		SzRadio.setTitle(inputFilter.filter(radio.getTitle()));
        SzRadio.setServer(inputFilter.filter(radio.getServer()));
        SzRadio.setNote(inputFilter.filter(radio.getNote()));
		
        tx.commit();
		session.flush();
    }

    public void saveOrupdate(SzRadio radio){
        getSession().saveOrUpdate(radio);
    }
}
